#ifndef _UI_ENABLER_H_
#define _UI_ENABLER_H_

#include "ui_widget.h"
#include "math/vec4.h"

namespace ui
{
class UIEnablerIDMapper;
class UIEnabler
{
public:
	UIEnabler();
	~UIEnabler();

	static UIEnabler&	Instance();

	void				Load(const std::string& File, const std::string& Header = "UIList"); // load appropriate data file
	void				RefreshUI(int Level = -1, bool ActivateEvent = true); // update UI based on arbitrary "Level" value

	// accessors
	void				SetCurrentLevel(int Level)					{ m_CurLevel = Level; }
	int					GetCurrentLevel() const						{ return m_CurLevel; }
	void				SetIDMapper(UIEnablerIDMapper* p = NULL)	{ m_pIDMapper = p; }
	UIEnablerIDMapper*	GetIDMapper()								{ return m_pIDMapper; }

	// events
	bool				OnUIChanged(UIWidget* pWidget); // call when relevant UI properties have been changed externally
	bool				OnUIDeleted(UIWidget* pWidget); // call when UI is deleted (should happen extremely rarely, I suppose)

	// callbacks
	typedef void		(*UIActivateEventCB)(UIWidget* pWidget, int ID, void* pvData);
	void				SetActivateEventCB(UIActivateEventCB pFunc = NULL, void* pvData = NULL);

	typedef				util::Delegate2<UIWidget*, int>								tdgUIActivateEvent;
	void				SetActivateEventDg(const tdgUIActivateEvent& pFunc = NULL)	{ m_pActivateFunc = pFunc; }

private:
	struct UI_ENABLER_DATA
	{
		UIWidget*		pWidget;		// offending widget
		math::Vec4		BaseColor;		// original color of widget; save for reference
		int				ID;				// custom identifier
		int				MinLevel;		// minimum Level where this widget becomes available
		float			DoColor;		// does disabling affect widget color? 0.0f-1.0f
		bool			DoEnable;		// does disabling affect active state? true/false
		bool			DoVisible;		// does disabling affect visibility? true/false

		std::string		OnActivate;		// run script the first time widget becomes enabled?

	// internal variables
		bool			IsActivated;
	};
	std::vector<UI_ENABLER_DATA>	m_UIList;

	int					m_CurLevel;
	UIActivateEventCB	m_pActivateCB;
	void*				m_pvActivateData;
	tdgUIActivateEvent	m_pActivateFunc;

	UIEnablerIDMapper*	m_pIDMapper;
};


class UIEnablerIDMapper
{
public:
	UIEnablerIDMapper();
	virtual ~UIEnablerIDMapper();

	virtual std::string	MapIDToString(int ID) = 0;
	virtual int			MapStringToID(const std::string& ID) = 0;
};
}; // namespace ui

#endif //_UI_ENABLER_H_
